package com.sgl.gk.tools;

import com.alibaba.fastjson.JSON;
import com.sgl.gk.domain.plc.OpcUa;
import com.sgl.gk.domain.plc.OpcUaList;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;

/**
 * @author:xuenci
 * @date:2023/5/19 9:25
 **/
public class ReadOpcUaNodeInfoTool {

    public static OpcUaList GetOpcUaList(){
        Path filepath = Paths.get("D:/sg/jdk/bin/config/dev/comm-opc-ua.json");
//        Path filepath = Paths.get("./comm-opc-ua.json");
        StringBuilder sb = new StringBuilder();
        try {
            BufferedReader reader = Files.newBufferedReader(filepath);
            String line;
            while ((line = reader.readLine())!= null){
                sb.append(line);
                sb.append(System.lineSeparator());
            }
            reader.close();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        String content = sb.toString();
        OpcUaList opcUaList = JSON.parseObject(content, OpcUaList.class);
        return opcUaList;
    }

}
